package com.taobao.txc.parser.hint;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.taobao.txc.common.b.c;
import com.taobao.txc.common.util.c.g;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;

public class TddlHint
{
  public static String getTddlHint(String paramString)
  {
    return g.b(paramString, "/*+TDDL(", ")*/");
  }
  
  public static String removeTddlHint(String paramString)
  {
    String str = getTddlHint(paramString);
    if ((str == null) || (str.isEmpty())) {
      return paramString;
    }
    return g.a(paramString, "/*+TDDL(", ")*/").trim();
  }
  
  public static Map<String, String> getTddlHintMap(String paramString)
  {
    String str1 = getTddlHint(paramString);
    if ((str1 == null) || (str1.isEmpty())) {
      return null;
    }
    LinkedHashMap localLinkedHashMap = new LinkedHashMap();
    try
    {
      Map localMap = (Map)JSON.parseObject(str1, Map.class);
      Iterator localIterator = localMap.keySet().iterator();
      while (localIterator.hasNext())
      {
        String str2 = (String)localIterator.next();
        Object localObject = localMap.get(str2);
        localLinkedHashMap.put(str2, localObject.toString());
      }
    }
    catch (Exception localException)
    {
      throw new c(localException, "hint parse error");
    }
    return localLinkedHashMap;
  }
  
  public static String buildHintSql(Map<String, String> paramMap, String paramString)
  {
    if ((paramMap == null) || (paramMap.size() == 0)) {
      return paramString;
    }
    return buildTddlHint(paramMap) + " " + removeTddlHint(paramString);
  }
  
  public static String buildTddlHint(Map<String, String> paramMap)
  {
    if ((paramMap == null) || (paramMap.size() == 0)) {
      return "";
    }
    StringBuilder localStringBuilder = new StringBuilder();
    localStringBuilder.append("/*+TDDL(");
    localStringBuilder.append(JSON.toJSONString(paramMap, new SerializerFeature[] { SerializerFeature.UseSingleQuotes }));
    localStringBuilder.append(")*/");
    return localStringBuilder.toString();
  }
  
  public static String getTxcXid(String paramString)
  {
    Map localMap = getTddlHintMap(paramString);
    if ((localMap == null) || (localMap.size() == 0)) {
      return null;
    }
    String str = "";
    try
    {
      str = (String)localMap.get("TXC_XID");
      if ((str == null) || (str.length() == 0)) {
        return null;
      }
    }
    catch (Exception localException)
    {
      throw new c(localException, "xid parse error");
    }
    return str;
  }
  
  public static String addTxcXid(String paramString1, String paramString2)
  {
    Object localObject = getTddlHintMap(paramString2);
    if ((localObject == null) || (((Map)localObject).size() == 0)) {
      localObject = new LinkedHashMap();
    }
    ((Map)localObject).put("TXC_XID", String.format("%s", new Object[] { paramString1 }));
    return buildHintSql((Map)localObject, paramString2);
  }
  
  public static String removeTxcXid(String paramString)
  {
    Map localMap = getTddlHintMap(paramString);
    if ((localMap == null) || (localMap.size() == 0)) {
      return paramString;
    }
    localMap.remove("TXC_XID");
    return buildHintSql(localMap, paramString);
  }
}


/* Location:           C:\Users\ibm\Downloads\txc-yun-sample (1)\txc-yun-sample\lib\txc-client-2.0.72.jar
 * Qualified Name:     com.taobao.txc.parser.hint.TddlHint
 * JD-Core Version:    0.7.0.1
 */